/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.model.relate.relateop;

import static chunmap.model.relate.IntersectionMatrix.*;
import chunmap.model.geom.GeoPoint;
import chunmap.model.geom.Geometry;
import chunmap.model.geom.Ring;
import chunmap.model.geom.Polygon;
import chunmap.model.relate.ComputeIm;

/**
 * disjion,onBoundary,within
 * 
 * @author chunquedong
 * 
 */
public class Point_Polygon extends ComputeIm {

	public Point_Polygon(GeoPoint p1, Polygon a2) {
		g1 = p1;
		g2 = a2;
	}

	@Override
	protected int inner2innerDim(Geometry g1, Geometry g2) {
		if (im.get(Inner, Border) != EmptyDim) {
			return EmptyDim;
		}

		GeoPoint p1 = (GeoPoint) g1;
		Polygon a2 = (Polygon) g2;
		if (a2.getShell().containIn(p1.getCoordinate())) {
			for (Ring r : a2.getHoles()) {
				if (r.containIn(p1.getCoordinate())) {
					return EmptyDim;
				}
			}
			return PointDim;
		}
		return EmptyDim;
	}

	@Override
	protected boolean within(Geometry g1, Geometry g2) {
		if (im.get(Inner, Border) != EmptyDim)
			return true;
		if (im.get(Inner, Inner) != EmptyDim)
			return true;
		else
			return false;
	}

}